package com.water.camera.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.MediaItem;
import androidx.media3.exoplayer.ExoPlayer;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.water.camera.bean.MediaData;
import com.water.camera.databinding.FragmentVideoBinding;

public class VideoFragment extends BaseFragment {

    FragmentVideoBinding binding;
    MediaData data;
    ExoPlayer player = null;
    int index;

    public VideoFragment setVideo(MediaData data, int i) {
        this.data = data;
        this.index = i;
        return this;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragmentVideoBinding.inflate(inflater, container, false);
//        Glide.with(getActivity())
//                .setDefaultRequestOptions(new RequestOptions())
//                .load(data.getPath())
//                .into(binding.cover);

        return binding.getRoot();
    }

    public void setPlayer(ExoPlayer player) {
        binding.cover.setVisibility(View.INVISIBLE);
        binding.playerView.setPlayer(player);
        MediaItem item = MediaItem.fromUri(data.getPath());
        player.setMediaItem(item);
        player.prepare();
        player.setPlayWhenReady(false);
    }
}
